//
// Created by LONG on 2020/10/17.
//

#include <NR_BCCH-BCH-Message.h>
#include "../include/rrcMsgBuilder.h"

//int32_t NGAP_BuildrrcSetup(void)
//{
//    NR_DL_CCCH_Message_t DLCCCHMessage;
//    DLCCCHMessage.message.present = NR_DL_CCCH_MessageType_PR_c1;
//    DLCCCHMessage.message.choice.c1->present = NR_DL_CCCH_MessageType__c1_PR_rrcSetup;
//    DLCCCHMessage.message.choice.c1->choice.rrcSetup = OS_MemCalloc(1, sizeof(NR_RRCSetup_t));
//
//    NR_RRCSetup_t *rrcSetup = DLCCCHMessage.message.choice.c1->choice.rrcSetup;
//    rrcSetup->rrc_TransactionIdentifier = 1;
//    rrcSetup->criticalExtensions.present = NR_RRCSetup__criticalExtensions_PR_rrcSetup;
//
//    rrcSetup->criticalExtensions.choice.rrcSetup = OS_MemCalloc(1, sizeof(NR_RRCSetup_IEs_t));
//
//    NR_RRCSetup_IEs_t *RRCSetup_IEs = rrcSetup->criticalExtensions.choice.rrcSetup;
//
//    /* List1 srb_ToAddModList OPTIONAL*/
//    NR_SRB_ToAddMod_t *ie = ASN1_MemCalloc(1, sizeof(NR_SRB_ToAddMod_t));
//    ASN_SEQUENCE_ADD(&RRCSetup_IEs->radioBearerConfig.srb_ToAddModList, ie);
//    ie->srb_Identity = 1;
////    ie->reestablishPDCP;	/* OPTIONAL */
////    ie->discardOnPDCP;	/* OPTIONAL */
//    ie->pdcp_Config = ASN1_MemCalloc(1, sizeof(NR_PDCP_Config_t));
//    ie->pdcp_Config->t_Reordering = ASN1_MemCalloc(1, sizeof(long));
//    *(ie->pdcp_Config->t_Reordering) = 35;
//    /* List2 drb_ToAddModList OPTIONAL*/
//    /* List3 drb_ToReleaseList OPTIONAL*/
//    /* srb3_ToRelease OPTIONAL*/
//
//    RRCSetup_IEs->masterCellGroup = "1";
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuildrrcReject(void)
//{
//    NR_DL_CCCH_Message_t DLCCCHMessage;
//    DLCCCHMessage.message.present = NR_DL_CCCH_MessageType_PR_c1;
//    DLCCCHMessage.message.choice.c1->present = NR_DL_CCCH_MessageType__c1_PR_rrcReject;
//    DLCCCHMessage.message.choice.c1->choice.rrcReject = OS_MemCalloc(1, sizeof(NR_RRCReject_t));
//
//    NR_RRCReject_t *RRCReject = DLCCCHMessage.message.choice.c1->choice.rrcReject;
//    RRCReject->criticalExtensions.present = NR_RRCReject__criticalExtensions_PR_rrcReject;
//
//    RRCReject->criticalExtensions.choice.rrcReject = OS_MemCalloc(1, sizeof(NR_RRCReject_IEs_t));
//
//    NR_RRCReject_IEs_t *RRCReject_IEs = RRCReject->criticalExtensions.choice.rrcReject;
//    RRCReject_IEs->waitTime = OS_MemCalloc(1, sizeof(NR_RejectWaitTime_t));
//    *RRCReject_IEs->waitTime = 1000;
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuildSecurityModeCommand(void)
//{
//    NR_DL_DCCH_Message_t DLDCCHMessage;
//    DLDCCHMessage.message.present = NR_DL_DCCH_MessageType_PR_c1;
//    DLDCCHMessage.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_securityModeCommand;
//    DLDCCHMessage.message.choice.c1->choice.securityModeCommand = OS_MemCalloc(1, sizeof(NR_SecurityModeCommand_t));
//
//    NR_SecurityModeCommand_t *SecurityModeCommand = DLDCCHMessage.message.choice.c1->choice.securityModeCommand;
//    SecurityModeCommand->rrc_TransactionIdentifier = 1;
//    SecurityModeCommand->criticalExtensions.present = NR_SecurityModeCommand__criticalExtensions_PR_securityModeCommand;
//
//    SecurityModeCommand->criticalExtensions.choice.securityModeCommand = OS_MemCalloc(1, sizeof(NR_SecurityModeCommand_IEs_t));
//
//    NR_SecurityModeCommand_IEs_t *securityModeCommand = SecurityModeCommand->criticalExtensions.choice.securityModeCommand;
//    securityModeCommand->securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm = NR_CipheringAlgorithm_nea0;
//    securityModeCommand->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm = OS_MemCalloc(1, sizeof(NR_IntegrityProtAlgorithm_t));
//    *securityModeCommand->securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm = NR_IntegrityProtAlgorithm_nia0;
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuildrrcRelease(void)
//{
//    NR_DL_DCCH_Message_t DLDCCHMessage;
//    DLDCCHMessage.message.present = NR_DL_DCCH_MessageType_PR_c1;
//    DLDCCHMessage.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_rrcRelease;
//    DLDCCHMessage.message.choice.c1->choice.rrcRelease = OS_MemCalloc(1, sizeof(NR_RRCRelease_t));
//
//    NR_RRCRelease_t *RRCRelease = DLDCCHMessage.message.choice.c1->choice.rrcRelease;
//    RRCRelease->rrc_TransactionIdentifier = 1;
//    RRCRelease->criticalExtensions.present = NR_RRCRelease__criticalExtensions_PR_rrcRelease;
//
////    RRCRelease->criticalExtensions.choice.rrcRelease = OS_MemCalloc(1, sizeof(NR_RRCRelease_IEs_t));
//
//    /* 什么参数都不带  */
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuilddlInformationTransfer (void)
//{
//    NR_DL_DCCH_Message_t DLDCCHMessage;
//    DLDCCHMessage.message.present = NR_DL_DCCH_MessageType_PR_c1;
//    DLDCCHMessage.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer;
//    DLDCCHMessage.message.choice.c1->choice.dlInformationTransfer = OS_MemCalloc(1, sizeof(NR_DLInformationTransfer_t));
//
//    NR_DLInformationTransfer_t *DLInformationTransfer = DLDCCHMessage.message.choice.c1->choice.dlInformationTransfer;
//    DLInformationTransfer->rrc_TransactionIdentifier = 1;
//    DLInformationTransfer->criticalExtensions.present = NR_DLInformationTransfer__criticalExtensions_PR_dlInformationTransfer;
//
//    DLInformationTransfer->criticalExtensions.choice.dlInformationTransfer = OS_MemCalloc(1, sizeof(NR_DLInformationTransfer_IEs_t));
//
//    NR_DLInformationTransfer_IEs_t *dLInformationTransfer = DLInformationTransfer->criticalExtensions.choice.dlInformationTransfer;
//    dLInformationTransfer->dedicatedNAS_Message = OS_MemCalloc(1, sizeof(NR_DedicatedNAS_Message_t));
//    *dLInformationTransfer->dedicatedNAS_Message = "11111111111111111111111";
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuildueCapabilityEnquiry(void)
//{
//    NR_DL_DCCH_Message_t DLDCCHMessage;
//    DLDCCHMessage.message.present = NR_DL_DCCH_MessageType_PR_c1;
//    DLDCCHMessage.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry;
//    DLDCCHMessage.message.choice.c1->choice.ueCapabilityEnquiry = OS_MemCalloc(1, sizeof(NR_UECapabilityEnquiry_t));
//
//    NR_UECapabilityEnquiry_t *UECapabilityEnquiry = DLDCCHMessage.message.choice.c1->choice.ueCapabilityEnquiry;
//    UECapabilityEnquiry->rrc_TransactionIdentifier = 1;
//    UECapabilityEnquiry->criticalExtensions.present = NR_UECapabilityEnquiry__criticalExtensions_PR_ueCapabilityEnquiry;
//
//    UECapabilityEnquiry->criticalExtensions.choice.ueCapabilityEnquiry = OS_MemCalloc(1, sizeof(NR_UECapabilityEnquiry_IEs_t));
//    NR_UECapabilityEnquiry_IEs_t *UECapabilityEnquiry_IEs = UECapabilityEnquiry->criticalExtensions.choice.ueCapabilityEnquiry;
//    UECapabilityEnquiry_IEs->ue_CapabilityEnquiryExt = OS_MemCalloc(1, sizeof(NR_DedicatedNAS_Message_t));
//
//    NR_UE_CapabilityRAT_Request_t *ie1 = ASN1_MemCalloc(1, sizeof(NR_UE_CapabilityRAT_Request_t));
//    ASN_SEQUENCE_ADD(&UECapabilityEnquiry_IEs->ue_CapabilityRAT_RequestList, ie1);
//    ie1->rat_Type = NR_RAT_Type_nr;
//
//    NR_UE_CapabilityRAT_Request_t *ie2 = ASN1_MemCalloc(1, sizeof(NR_UE_CapabilityRAT_Request_t));
//    ASN_SEQUENCE_ADD(&UECapabilityEnquiry_IEs->ue_CapabilityRAT_RequestList, ie2);
//    ie2->rat_Type = NR_RAT_Type_eutra_nr;
//
//    NR_UE_CapabilityRAT_Request_t *ie3 = ASN1_MemCalloc(1, sizeof(NR_UE_CapabilityRAT_Request_t));
//    ASN_SEQUENCE_ADD(&UECapabilityEnquiry_IEs->ue_CapabilityRAT_RequestList, ie3);
//    ie3->rat_Type = NR_RAT_Type_eutra;
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuildrrcReconfiguration(Uint32 drbNum)
//{
//    NR_DL_DCCH_Message_t DLDCCHMessage;
//    DLDCCHMessage.message.present = NR_DL_DCCH_MessageType_PR_c1;
//    DLDCCHMessage.message.choice.c1->present = NR_DL_DCCH_MessageType__c1_PR_rrcReconfiguration;
//    DLDCCHMessage.message.choice.c1->choice.rrcReconfiguration = OS_MemCalloc(1, sizeof(NR_RRCReconfiguration_t));
//
//    NR_RRCReconfiguration_t *RRCReconfiguration = DLDCCHMessage.message.choice.c1->choice.rrcReconfiguration;
//    RRCReconfiguration->rrc_TransactionIdentifier = 1;
//    RRCReconfiguration->criticalExtensions.present = NR_RRCReconfiguration__criticalExtensions_PR_rrcReconfiguration;
//
//    RRCReconfiguration->criticalExtensions.choice.rrcReconfiguration = OS_MemCalloc(1, sizeof(NR_RRCReconfiguration_IEs_t));
//    NR_RRCReconfiguration_IEs_t *RRCReconfiguration_IEs = RRCReconfiguration->criticalExtensions.choice.rrcReconfiguration;
//    RRCReconfiguration_IEs->radioBearerConfig = OS_MemCalloc(1, sizeof(NR_RadioBearerConfig_t));
//
//    RRCReconfiguration_IEs->radioBearerConfig->srb_ToAddModList = OS_MemCalloc(1, sizeof(NR_SRB_ToAddModList_t));
//
//    NR_SRB_ToAddMod_t *ie1 = ASN1_MemCalloc(1, sizeof(NR_SRB_ToAddMod_t));
//    ASN_SEQUENCE_ADD(&RRCReconfiguration_IEs->radioBearerConfig->srb_ToAddModList, ie1);
//    ie1->srb_Identity = 1;
//    ie1->pdcp_Config = ASN1_MemCalloc(1, sizeof(NR_PDCP_Config_t));
//    ie1->pdcp_Config->t_Reordering = ASN1_MemCalloc(1, sizeof(long));
//    *(ie1->pdcp_Config->t_Reordering) = 35;
//
//    if(drbNum)
//    {
//        RRCReconfiguration_IEs->radioBearerConfig->drb_ToAddModList = OS_MemCalloc(1, sizeof(NR_DRB_ToAddModList_t));
//
//        NR_DRB_ToAddMod_t *ieDrb = ASN1_MemCalloc(1, sizeof(NR_DRB_ToAddMod_t));
//        ASN_SEQUENCE_ADD(&RRCReconfiguration_IEs->radioBearerConfig->drb_ToAddModList, ie1);
//
//        ieDrb->cnAssociation = ASN1_MemCalloc(1, sizeof(NR_DRB_ToAddMod__cnAssociation));
//        ieDrb->cnAssociation->present = NR_DRB_ToAddMod__cnAssociation_PR_sdap_Config;
//        ieDrb->cnAssociation->choice.sdap_Config = ASN1_MemCalloc(1, sizeof(NR_SDAP_Config_t));
//
//        NR_SDAP_Config_t *SDAP_Config = ieDrb->cnAssociation->choice.sdap_Config;
//        SDAP_Config->pdu_Session = 5;
//        SDAP_Config->sdap_HeaderDL = 1;
//        SDAP_Config->sdap_HeaderUL = 0;
//        SDAP_Config->defaultDRB = 1;
//        SDAP_Config->mappedQoS_FlowsToAdd = ASN1_MemCalloc(1, sizeof(NR_SDAP_Config__mappedQoS_FlowsToAdd));
//
//        NR_QFI_t *QFI = ASN1_MemCalloc(1, sizeof(NR_QFI_t));
//        ASN_SEQUENCE_ADD(&SDAP_Config->mappedQoS_FlowsToAdd, QFI);
//        *QFI = 1;
//
//        ieDrb->drb_Identity = 1;
//        ieDrb->pdcp_Config = ASN1_MemCalloc(1, sizeof(NR_PDCP_Config_t));
//        ieDrb->pdcp_Config->drb = ASN1_MemCalloc(1, sizeof(NR_PDCP_Config__drb));
//
//        NR_PDCP_Config__drb *drb = ieDrb->pdcp_Config->drb;
//        drb->discardTimer = ASN1_MemCalloc(1, sizeof(long));
//        *drb->discardTimer = 15;
//
//        drb->pdcp_SN_SizeUL = ASN1_MemCalloc(1, sizeof(long));
//        *drb->pdcp_SN_SizeUL = 1;
//
//        drb->pdcp_SN_SizeDL = ASN1_MemCalloc(1, sizeof(long));
//        *drb->pdcp_SN_SizeDL = 1;
//
//        drb->headerCompression->present = NR_PDCP_Config__drb__headerCompression_PR_notUsed;
//
//        drb->integrityProtection = ASN1_MemCalloc(1, sizeof(long));
//        *drb->integrityProtection = 0;
//
//        drb->statusReportRequired = ASN1_MemCalloc(1, sizeof(long));
//        *drb->statusReportRequired = 0;
//
//        ieDrb->pdcp_Config->t_Reordering = ASN1_MemCalloc(1, sizeof(long));
//        *ieDrb->pdcp_Config->t_Reordering = 18;
//    }
//
//    RRCReconfiguration_IEs->nonCriticalExtension = ASN1_MemCalloc(1, sizeof(NR_RRCReconfiguration_v1530_IEs_t));
//
//    RRCReconfiguration_IEs->nonCriticalExtension->masterCellGroup = ASN1_MemCalloc(1, sizeof(OCTET_STRING_t));
//    *RRCReconfiguration_IEs->nonCriticalExtension->masterCellGroup = "232323";
//
//    RRCReconfiguration_IEs->nonCriticalExtension->dedicatedNAS_MessageList = ASN1_MemCalloc(1, sizeof(NR_RRCReconfiguration_v1530_IEs__dedicatedNAS_MessageList));
//
//    NR_DedicatedNAS_Message_t *item = ASN1_MemCalloc(1, sizeof(NR_DedicatedNAS_Message_t));
//    ASN_SEQUENCE_ADD(&RRCReconfiguration_IEs->nonCriticalExtension->dedicatedNAS_MessageList->list, item);
//    item = "888888888888888";
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuildrrcSetupRequest(void)
//{
//    NR_UL_CCCH_Message_t ULCCCH_Message;
//    ULCCCH_Message.message.present = NR_UL_CCCH_MessageType_PR_c1;
//    ULCCCH_Message.message.choice.c1->present = NR_UL_CCCH_MessageType__c1_PR_rrcSetupRequest;
//    ULCCCH_Message.message.choice.c1->choice.rrcSetupRequest = OS_MemCalloc(1, sizeof(NR_RRCSetupRequest_t));
//
//    NR_RRCSetupRequest_t *rrcSetupRequest = ULCCCH_Message.message.choice.c1->choice.rrcSetupRequest;
//    rrcSetupRequest->rrcSetupRequest.ue_Identity.present = NR_InitialUE_Identity_PR_ng_5G_S_TMSI_Part1;
//    rrcSetupRequest->rrcSetupRequest.ue_Identity.choice.ng_5G_S_TMSI_Part1 = "2323";
//    rrcSetupRequest->rrcSetupRequest.establishmentCause = NR_EstablishmentCause_mt_Access;
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuildrrcSetupComplete(void)
//{
//    NR_UL_DCCH_Message_t ULDCCH_Message;
//    ULDCCH_Message.message.present = NR_UL_DCCH_MessageType_PR_c1;
//    ULDCCH_Message.message.choice.c1->present = NR_UL_DCCH_MessageType__c1_PR_rrcSetupComplete;
//    ULDCCH_Message.message.choice.c1->choice.rrcSetupComplete = OS_MemCalloc(1, sizeof(NR_RRCSetupComplete_t));
//
//    NR_RRCSetupComplete_t *rrcSetupComplete = ULDCCH_Message.message.choice.c1->choice.rrcSetupComplete;
//    rrcSetupComplete->rrc_TransactionIdentifier = 1;
//    rrcSetupComplete->criticalExtensions.present = NR_RRCSetupComplete__criticalExtensions_PR_rrcSetupComplete;
//    rrcSetupComplete->criticalExtensions.choice.rrcSetupComplete = OS_MemCalloc(1, sizeof(NR_RRCSetupComplete_IEs_t));
//
//    NR_RRCSetupComplete_IEs_t *rrcSetupComplete_IEs = rrcSetupComplete->criticalExtensions.choice.rrcSetupComplete;
//    rrcSetupComplete_IEs->selectedPLMN_Identity = 1;
//    rrcSetupComplete_IEs->dedicatedNAS_Message = "44444444444";
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuildulInformationTransfer(void)
//{
//    NR_UL_DCCH_Message_t ULDCCH_Message;
//    ULDCCH_Message.message.present = NR_UL_DCCH_MessageType_PR_c1;
//    ULDCCH_Message.message.choice.c1->present = NR_UL_DCCH_MessageType__c1_PR_ulInformationTransfer;
//    ULDCCH_Message.message.choice.c1->choice.ulInformationTransfer = OS_MemCalloc(1, sizeof(NR_ULInformationTransfer_t));
//
//    NR_ULInformationTransfer_t *ULInformationTransfer = ULDCCH_Message.message.choice.c1->choice.ulInformationTransfer;
//    ULInformationTransfer->criticalExtensions.present = NR_ULInformationTransfer__criticalExtensions_PR_ulInformationTransfer;
//    ULInformationTransfer->criticalExtensions.choice.ulInformationTransfer = OS_MemCalloc(1, sizeof(NR_ULInformationTransfer_IEs_t));
//
//    NR_ULInformationTransfer_IEs_t *ULInformationTransfer_IEs = ULInformationTransfer->criticalExtensions.choice.ulInformationTransfer;
//    ULInformationTransfer_IEs->dedicatedNAS_Message = OS_MemCalloc(1, sizeof(NR_DedicatedNAS_Message_t));
//    *ULInformationTransfer_IEs->dedicatedNAS_Message = "44444444444";
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuilsecurityModeComplete(void)
//{
//    NR_UL_DCCH_Message_t ULDCCH_Message;
//    ULDCCH_Message.message.present = NR_UL_DCCH_MessageType_PR_c1;
//    ULDCCH_Message.message.choice.c1->present = NR_UL_DCCH_MessageType__c1_PR_securityModeComplete;
//    ULDCCH_Message.message.choice.c1->choice.securityModeComplete = OS_MemCalloc(1, sizeof(NR_SecurityModeComplete_t));
//
//    NR_SecurityModeComplete_t *SecurityModeComplete = ULDCCH_Message.message.choice.c1->choice.securityModeComplete;
//    SecurityModeComplete->rrc_TransactionIdentifier = 1;
//    SecurityModeComplete->criticalExtensions.present = NR_SecurityModeComplete__criticalExtensions_PR_securityModeComplete;
////	SecurityModeComplete->criticalExtensions.choice.securityModeComplete = OS_MemCalloc(1, sizeof(NR_SecurityModeComplete_IEs_t));
//
//    /* 什么参数都不带  */
//
//    return O5G_RC_OK;
//}
//
//int32_t NGAP_BuilrrcReconfigurationComplete(void)
//{
//    NR_UL_DCCH_Message_t ULDCCH_Message;
//    ULDCCH_Message.message.present = NR_UL_DCCH_MessageType_PR_c1;
//    ULDCCH_Message.message.choice.c1->present = NR_UL_DCCH_MessageType__c1_PR_rrcReconfigurationComplete;
//    ULDCCH_Message.message.choice.c1->choice.rrcReconfigurationComplete = OS_MemCalloc(1, sizeof(NR_RRCReconfigurationComplete_t));
//
//    NR_RRCReconfigurationComplete_t *rrcReconfigurationComplete = ULDCCH_Message.message.choice.c1->choice.rrcReconfigurationComplete;
//    rrcReconfigurationComplete->rrc_TransactionIdentifier = 1;
//    rrcReconfigurationComplete->criticalExtensions.present = NR_RRCReconfigurationComplete__criticalExtensions_PR_rrcReconfigurationComplete;
////	rrcReconfigurationComplete->criticalExtensions.choice.rrcReconfigurationComplete = OS_MemCalloc(1, sizeof(NR_RRCReconfigurationComplete_IEs_t));
//
//    /* 什么参数都不带  */
//
//    return O5G_RC_OK;
//}

int32_t RRC_BuildMib(uint32_t nbIdx, uint32_t cellIdx)
{
    char *mibBuffer;
    uint32_t mibBuffSize;
    asn_enc_rval_t asn1EncRc;

    NR_BCCH_BCH_Message_t mib;

    mibBuffer = gpRanL3Context->nbInst[nbIdx].cellInst[cellIdx].mibBuffer;
    mibBuffSize = sizeof(gpRanL3Context->nbInst[nbIdx].cellInst[cellIdx].mibBuffer);

    memset(&mib, 0, sizeof(NR_BCCH_BCH_Message_t));
    mib.message.present = NR_BCCH_BCH_MessageType_PR_mib;
    mib.message.choice.mib = ASN1_MemCalloc(1, sizeof(struct NR_MIB));
    memset(mib.message.choice.mib, 0, sizeof(struct NR_MIB));
    //36.331 SFN BIT STRING (SIZE (8)  , 38.331 SFN BIT STRING (SIZE (6))
    uint8_t sfnMsb = (uint8_t)(0x4 & 0x3f);
    mib.message.choice.mib->systemFrameNumber.buf = ASN1_MemCalloc(1, sizeof(uint8_t));
    mib.message.choice.mib->systemFrameNumber.buf[0] = sfnMsb << 2;
    mib.message.choice.mib->systemFrameNumber.size = 1;
    mib.message.choice.mib->systemFrameNumber.bits_unused = 2;
    //38.331 spare BIT STRING (SIZE (1))
    uint16_t* spare = ASN1_MemCalloc(1, sizeof(uint16_t));

    mib.message.choice.mib->spare.buf = (uint8_t*)spare;
    mib.message.choice.mib->spare.size = 1;
    mib.message.choice.mib->spare.bits_unused = 7;  // This makes a spare of 1 bits

    mib.message.choice.mib->ssb_SubcarrierOffset = (31) & 15;
    mib.message.choice.mib->pdcch_ConfigSIB1.controlResourceSetZero = 0;
    mib.message.choice.mib->pdcch_ConfigSIB1.searchSpaceZero = 0;
    mib.message.choice.mib->subCarrierSpacingCommon = NR_MIB__subCarrierSpacingCommon_scs15or60;
    mib.message.choice.mib->dmrs_TypeA_Position = NR_MIB__dmrs_TypeA_Position_pos2;

    //  assign_enum
    mib.message.choice.mib->cellBarred = NR_MIB__cellBarred_notBarred;
    //  assign_enum
    mib.message.choice.mib->intraFreqReselection = NR_MIB__intraFreqReselection_notAllowed;
    //encode MIB to data
    asn1EncRc = uper_encode_to_buffer(&asn_DEF_NR_BCCH_BCH_Message, NULL, &mib, mibBuffer, mibBuffSize);
    ASN_STRUCT_RESET(asn_DEF_NR_BCCH_BCH_Message, &mib);
    if (-1 == asn1EncRc.encoded)
    {
        return O5G_RC_ER;
    }
    gpRanL3Context->nbInst[nbIdx].cellInst[cellIdx].mibSize = CEIL_DIVIDE_INT(asn1EncRc.encoded, 8);
    CSP_LOG_MEM(RAN_MD_L3_COMM, LOG_LVL_DBG, mibBuffer, CEIL_DIVIDE_INT(asn1EncRc.encoded, 8));

    return O5G_RC_OK;
}
